package com.yunupmall.mapper.commoditymapper;


import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.yunupmall.api.fordentity.Commodity;
import com.yunupmall.api.fordentity.Specs;
import com.yunupmall.api.fordentity.SpecsCommodity;
import com.yunupmall.entity.admin.commoditypojo.*;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.util.List;

@Mapper
@Repository
public interface CommodityMapper extends BaseMapper<Commodity> {
    @Select("SELECT c.id,c.c_name,c.c_price,c.exampleImage1,c.status,k.k_name,b.b_name from commodity c LEFT OUTER JOIN Kind k on c.kind_id=k.id LEFT OUTER JOIN brand b on c.brand_id=b.id  LIMIT #{Thispage},#{Sizepage}")
    List<Commodity> selectDate(@Param("Thispage") int thispage, @Param("Sizepage") int sizepage);

    //查询总条数，分页
    @Select("SELECT COUNT(*) as counts from commodity")
    KindCount getKindCount();

    //按条件进行检索
    List<Commodity> getcommoditywhereDate(CommodityWhere commodityWhere);

    //条件检索数据量
    int getDataCount(CommodityWhere commodityWhere);

    //检索该种类下的商品数据
    @Select("SELECT id,c_name,c_price from commodity where kind_id=#{k_id} LIMIT #{thispage},#{pagesize}")
    List<KindUpDate> queryKindUpdata(@Param("k_id") Integer k_id, @Param("thispage") Integer thispage, @Param("pagesize") Integer pagesize);

    @Select("select count(*) from commodity where kind_id=#{k_id}")
    int quetyCounts(@Param("k_id") Integer k_id);

    //获取商品最新ID
    @Select("select max(id) from commodity")
    int newcommotityID();

    //插入商品规格
    int insertcommotitySpecs(@Param("list") List<ResultAdd> specs, @Param("k_id") Integer id);

    //为新加的商品添加规格
    int AddceatecommotitySpecs(@Param("list") List<Specs> addcommtitySpecs, @Param("c_id") Integer cid);

    //添加新商品信息
    int insertCommtityData(AddCommotityimage addCommotityimage);

    //查看该类别下的商品规格名称
    @Select("select id,s_name from specs where k_id=#{k_id} GROUP BY s_name")
    List<SpecsName> quetyKind_specsList(@Param("k_id") Integer id);

    //查看规格值
    List<SpecsValues> querySpecsUpData(@Param("Specsname") String SpecsName, @Param("k_id") Integer k_id);

    //添加商品规格值
    int addcommotity_specsvalues(@Param("list") List<AllData> allData, @Param("c_id") Integer newSpecsID);

    //查询该产品ID下的规格
    @Select("select * from specs_commodity where c_id=#{c_id}")
    List<SpecsCommodity> queryThisDataList(@Param("c_id") Integer c_id);

    //删除商品数据以及SKU
    @Delete("delete from commodity where id=#{id}")
    int deleteCommtityThis(@Param("id") Integer id);

    @Delete("delete from specs_commodity where c_id=#{id}")
    int deleteCommtityThissku(@Param("c_id") Integer id);
}
